home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12734 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  44 lines

  1. Path: li.net!jeremy
  2. From: jeremy@newshost.li.net (Jeremy Markman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help!  Can't read input from keyboard!
  5. Date: 2 Apr 1996 14:39:10 GMT
  6. Organization: LI Net (Long Island Network)
  7. Message-ID: <4jre6e$op1@linet06.li.net>
  8. References: <4jq0ts$5mh@taniemarie.solon.com>
  9. NNTP-Posting-Host: linet04.li.net
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Peter Seebach (seebs@taniemarie.solon.com) wrote:
  13. : I guess I thought I knew C, but maybe not.  The following program compiles
  14.  
  15. Maybe Not...
  16.  
  17. First, the sscanf() function will read in input from a string.  You did 
  18. not specify a string, which is why you got an error originally when 
  19. compiling.
  20. Second, using scanf(), even when used correctly, is not recommended for 
  21. reading in user input.  Use the getch() function to read in one character 
  22. at a time from the keyboard, then parse the characters you read in to 
  23. make sure you are getting the input you are looking for.
  24. Here's a quick example:
  25.  
  26. int main()
  27.  { 
  28.   int ch;
  29.  
  30.   ch = getch();
  31.   printf("%c\n",ch);
  32.  
  33.   return(0);
  34.  }
  35.  
  36.  
  37. Old Code:
  38. :     int main(void) {
  39. :         int i = 0;
  40. :         (void) sscanf, "3", "%d", i;
  41. :         (void) printf, "%d", i;
  42. :         return 0;
  43. :     }
  44.